﻿
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BgObj : MonoBehaviour {

	[HideInInspector]
	public float width;
	[HideInInspector]
	public float offPreCloud;
	public bool canFloat;
	[HideInInspector]
	public float hight;
	[HideInInspector]
	public float low;
	[HideInInspector]
	private float floatSpeed = 0.5f;
	private bool isLow;
	public int type;
	// Use this for initialization
	void Start () {
		isLow = true;
		width = GetComponent<SpriteRenderer> ().bounds.size.x;
	}

	// Update is called once per frame
	void Update () {
		if (canFloat) {
			if (isLow && transform.position.y > low) {
				transform.position = new Vector3 (transform.position.x, transform.position.y - floatSpeed * Time.deltaTime, transform.position.z);
			}
			if(!isLow && transform.position.y < hight){
				transform.position = new Vector3 (transform.position.x, transform.position.y + floatSpeed * Time.deltaTime, transform.position.z);
			}
			if (transform.position.y <= low) {
				isLow = false;
			}
			if (transform.position.y >= hight) {
				isLow = true;
			}
		}
	}
}
